<template>
	<view class="mainpadding">
		<view class="sanshier xiaohei fonweight">可提现金额：{{ktx_money}}元</view>
		<view class="xiahuaxian flexleft margin_top2">
			<view class="bigtext xiaohei fonweight">￥</view>
			<input type="number" placeholder="请输入提现金额" v-model="price">
		</view>
		<view class="sanshier xiaohei fonweight margin_top">提现方式</view>
		<view class="flexbetween margin_top" @click="pay_type=1">
			<view class="flexleft ">
				<u-icon name="weixin-circle-fill" color="#50B674" size="24" class="margin_right1"></u-icon>
				<view class="sanshier xiaohei nofonweight ">微信提现</view>
			</view>
			<view class="">
				<u-icon class="" name="checkmark-circle-fill" v-if="pay_type!=1" color="#999" size="24"></u-icon>
				<u-icon class="" name="checkmark-circle-fill" v-if="pay_type==1" color="#1BA95B"
					size="24"></u-icon>
			</view>
		</view>
		<view class="flexbetween margin_top" @click="pay_type=2">
			<view class="flexleft">
				<u-icon name="zhifubao-circle-fill" color="#5A9EF7" size="24" class="margin_right1"></u-icon>
				<view class="sanshier xiaohei nofonweight ">支付宝提现</view>
			</view>
			<view class="">
				<u-icon class="" name="checkmark-circle-fill" v-if="pay_type!=2" color="#999" size="24"></u-icon>
				<u-icon class="" name="checkmark-circle-fill" v-if="pay_type==2" color="#1BA95B"
					size="24"></u-icon>
			</view>
		</view>
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="submit()">确定提现</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")

	export default {
		data() {
			return {
				userInfo: {},
				pay_type: 1, //支付方式:1=微信,2=支付宝
				type:1,//1余额提现，2财务管理提现
				ktx_money:0,
				user_zbfapply_listid:"",
				openid:""
			}
		},
		onLoad(options) {
			this.type = options.type
			if(options.user_zbfapply_listid){
				this.user_zbfapply_listid=options.user_zbfapply_listid
			}
			this.userinfomsg()
			this.getopenid()
		},
		methods: {
			getopenid(){
				let _this = this
				uni.login({
					success(res) {
						if (res.code) {
							httpRequest.request('/api/user/getopenid', 'GET', {
								code:res.code
							}).then(resp => {
								_this.openid = resp.data.openid
							}).catch(err=>{
							})
						}
					}
				})
			},
			userinfomsg() {
				let url = "/api/user/index"
				let data = {}
				if(this.type==2){
					url = "/api/user/zbfapplyCw"
					this.$set(data,"user_zbfapply_id",this.user_zbfapply_listid)
				}
				httpRequest.request(url, 'GET', data).then(res => {
					if(this.type==1){
						this.ktx_money = res.data.money
					}else{
						this.ktx_money = res.data.ss_price
					}
				})
			},
			submit(){
				if(Number(this.price)>Number(this.ktx_money)){
					httpRequest.toast("提现金额不可大于可提现金额")
					return false
				}
				let data = {
					price:this.price,
					type:this.pay_type
				}
				if(this.pay_type==1){//微信提现
					this.$set(data,"openid",this.openid)
				}
				let url = "/api/user/addWithdrawal"
				if(this.type==2){
					url = "/api/user/addZbfWithdrawal"
					this.$set(data,"user_zbfapply_id",this.user_zbfapply_listid)
				}
				httpRequest.request(url, 'GET', data).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.huibox {
		background: #F5F5F5;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
	}
</style>